#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int status;
    pid_t pc, pr;
    if ((pc = fork()) < 0)
    {
        printf("error in fork!");
        exit(1);
    }
    else if (pc == 0)
    {
        printf("This is child process with pid of %d.\n", getpid());
        exit(3); //子进程返回3
    }
    else
    {
        pr = wait(&status);
        if (WIFEXITED(status)) //返回值非零时用WEXITSTATUS(status)这个宏来提取子进程的返回值
        {
            //如果WIFEXITED返回非零值
            printf("the child process %d exit normally.\n", pr);
            printf("the return code is %d.\n", WEXITSTATUS(status)); //获取子进程的返回值
        }
        else //如果WIFEXITED返回零
        {
            printf("the child process %d exit abnormally.\n", pr);
        }
    }
    return 0;
}

// This is child process with pid of 33743.
// the child process 33743 exit normally.
// the return code is 3.
//